var e = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), a = require("../../../../@babel/runtime/helpers/asyncToGenerator"), t = require("../../../../mycomponent/payKeyboard/PayKeyboardAsync.js"), n = getApp();

Page({
    data: {
        language: "",
        transfer_multiple: 0,
        transfer_fetter: 0,
        recharge_value: "",
        recharge_id: "",
        recharge_search: "",
        ratio: 0,
        arrival_count: 0,
        buttonOff: !0,
        love_name: "",
        usable: 0,
        showSearch: !1,
        search_list: [],
        actualVal: "",
        sell_value: "",
        isclick: !0,
        memberInfo: {
            nickname: "",
            realname: ""
        },
        payKeyboardShow: !1,
        need_password: !1,
        has_password: !1,
        key: ""
    },
    onLoad: function(e) {
        e.key && this.setData({
            key: e.key
        });
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {
        this.data.isclick = !0, this.getUsable();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    searchTransfer: function(e) {
        var a = this, t = e.detail.replace(/\D/g, ""), r = "";
        "donate" == this.data.key ? (r = n.getNetAddresss("plugin.love.Frontend.Modules.Member.Controllers.query.index"), 
        r += "&recipient=" + t) : (r = n.getNetAddresss("plugin.love.Frontend.Controllers.team-dividend-search.index"), 
        r += "&search=" + t), t && (this.setData({
            memberInfo: {
                nickname: "",
                realname: ""
            }
        }), n._getNetWork({
            url: r,
            success: function(e) {
                if (1 === e.data.result) if ("donate" == a.data.key) {
                    var t = e.data.data.member;
                    t && a.setData({
                        showSearch: !0,
                        "memberInfo.nickname": t.username ? t.username : "",
                        "memberInfo.realname": t.realname ? t.realname : ""
                    });
                } else {
                    var r = e.data.data[0];
                    a.setData({
                        showSearch: !0,
                        "memberInfo.nickname": r.username ? r.username : "",
                        "memberInfo.realname": r.nickname ? r.nickname : ""
                    });
                } else a.setData({
                    showSearch: !1
                }), n.tips(e.data.msg);
            },
            fail: function(e) {
                console.log(e);
            }
        }));
    },
    searchTransfer_1: function() {
        var e = this, a = this.data.recharge_search;
        if (a) {
            this.setData({
                memberInfo: {
                    nickname: "",
                    realname: ""
                }
            });
            var t = "";
            "donate" == this.data.key ? (t = n.getNetAddresss("plugin.love.Frontend.Modules.Member.Controllers.query.index"), 
            t += "&recipient=" + a) : (t = n.getNetAddresss("plugin.love.Frontend.Controllers.team-dividend-search.index"), 
            t += "&search=" + a), n._getNetWork({
                url: t,
                success: function(a) {
                    if (1 === a.data.result) if ("donate" == e.data.key) {
                        var t = a.data.data.member;
                        t && e.setData({
                            showSearch: !0,
                            "memberInfo.nickname": t.username ? t.username : "",
                            "memberInfo.realname": t.realname ? t.realname : ""
                        });
                    } else {
                        var r = a.data.data[0];
                        e.setData({
                            showSearch: !0,
                            "memberInfo.nickname": r.username ? r.username : "",
                            "memberInfo.realname": r.nickname ? r.nickname : ""
                        });
                    } else e.setData({
                        showSearch: !1
                    }), n.tips(a.data.msg);
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }
    },
    getUsable: function() {
        var e = this, a = n.getNetAddresss("plugin.love.Frontend.Controllers.page.index");
        n._getNetWork({
            url: a,
            success: function(a) {
                if (1 === a.data.result) {
                    e.setData({
                        usable: a.data.data.usable,
                        love_name: a.data.data.love_name,
                        ratio: a.data.data.transfer_proportion,
                        transfer_multiple: a.data.data.transfer_multiple,
                        transfer_fetter: a.data.data.transfer_fetter,
                        need_password: a.data.data.transfer_password,
                        has_password: a.data.data.has_password,
                        point_name: a.data.data.point_name
                    }), e.need_sign = a.data.data.need_sign || !1, wx.setNavigationBarTitle({
                        title: "donate" == e.data.key ? a.data.data.love_name + e.data.point_name + "转赠" : a.data.data.love_name ? a.data.data.love_name + "转账" : "转账"
                    });
                    var t = e.data.recharge_value, n = e.data.ratio;
                    e.setData({
                        actualVal: t - t * n / 100
                    });
                } else wx.showToast({
                    title: a.data.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    payKeyboardComplete: function(e) {
        t.payKeyboardAsync.complete(e.detail);
    },
    getPayKeyboardPassword: function() {
        return this.setData({
            payKeyboardShow: !0
        }), new Promise(function(e, a) {
            t.payKeyboardAsync.addCompleteFn(function(a) {
                e(a);
            });
        });
    },
    payKeyboardClose: function() {
        this.setData({
            payKeyboardShow: !1
        });
    },
    getBalance: function() {
        var t = this;
        return a(e.default.mark(function a() {
            var r, s;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (t.data.isclick) {
                        e.next = 3;
                        break;
                    }
                    return wx.showToast({
                        title: "请勿重复点击",
                        icon: "none"
                    }), e.abrupt("return");

                  case 3:
                    if (!t.need_sign) {
                        e.next = 6;
                        break;
                    }
                    return wx.showModal({
                        title: "提示",
                        content: "请先完成合同签署",
                        success: function(e) {
                            e.confirm && wx.navigateTo({
                                url: "/packageH/sign_shopV2/index/index?scene=3"
                            });
                        }
                    }), e.abrupt("return");

                  case 6:
                    if (t.data.recharge_search) {
                        e.next = 9;
                        break;
                    }
                    return wx.showToast({
                        title: "请输入会员ID/手机号/昵称",
                        icon: "none"
                    }), e.abrupt("return");

                  case 9:
                    if (t.data.recharge_value) {
                        e.next = 12;
                        break;
                    }
                    return wx.showToast({
                        title: "请输入您要转账的数额",
                        icon: "none"
                    }), e.abrupt("return");

                  case 12:
                    if (t.data.showSearch) {
                        e.next = 14;
                        break;
                    }
                    return e.abrupt("return", n.tips("输入的值没有搜索到对应的用户"));

                  case 14:
                    if (1 != t.data.need_password || 0 != t.data.has_password) {
                        e.next = 20;
                        break;
                    }
                    return e.next = 17, n.confirm("请先设置支付密码");

                  case 17:
                    return e.sent && wx.navigateTo({
                        url: "/packageA/member/set_balance_password/set_balance_password"
                    }), e.abrupt("return");

                  case 20:
                    if (r = "", r = "donate" == t.data.key ? n.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.transfer-point.index") : n.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.transfer.index"), 
                    r += "&recipient=" + t.data.recharge_search, r += "&change_value=" + t.data.recharge_value, 
                    1 != t.data.need_password) {
                        e.next = 29;
                        break;
                    }
                    return e.next = 27, t.getPayKeyboardPassword();

                  case 27:
                    s = e.sent, r += "&password=" + s;

                  case 29:
                    t.data.isclick = !1, n._getNetWork({
                        url: r,
                        success: function(e) {
                            1 === e.data.result ? (wx.showToast({
                                title: e.data.msg,
                                icon: "none"
                            }), t.setData({
                                recharge_value: "",
                                recharge_search: ""
                            }), setTimeout(function() {
                                t.getUsable(), wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3)) : (t.data.isclick = !0, wx.showToast({
                                title: e.data.msg,
                                icon: "none"
                            }));
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });

                  case 31:
                  case "end":
                    return e.stop();
                }
            }, a);
        }))();
    },
    onChange: function(e) {
        this.setData({
            recharge_value: e.detail
        });
    },
    onChange2: function(e) {
        this.setData({
            recharge_search: e.detail.replace(/\D/g, "")
        });
    }
});